import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:龙宝
 * Date:2023-12-03
 * Time:10:31
 */
public class ShellSort {
    public static void main(String[] args) {
        int[] arr = {1,4,2,6,8,9,7,5,3,0};
        Sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    private static void Sort(int[] arr) {
        for(int i = arr.length/2;i!=0;i/=2) {
            //插入排序的思想
            for(int j = i;j < arr.length;j++) {
                int k = j - i;
                int start = arr[j];
                while (k >= 0) {
                    if(arr[k] > start) {
                        arr[k+i] = arr[k];
                        k -= i;
                    } else {
                        break;
                    }
                }
                arr[k+i] = start;
            }

        }
    }
}
